function getUserInfo () {
    $.ajax({
        url : 'login',
        method : 'get',
        success : function (body) {
            if (body.userId && body.userId > 0) {
                console.log('登录成功' + body.username)
                getBlogContent(body.userId)
                uploadVisit(body.userId)
            } else {
                alert('用户尚未登录！请登录后重试。')
                location.assign('blog_login.html')
            }
        },
        error : function () {
            alert('用户尚未登录！请登录后重试。')
            location.assign('blog_login.html')
        }
    })
}
getUserInfo()
function getBlogContent (user) {
    $.ajax({
        url : 'blog' + location.search,
        method : 'get',
        success : function (body) {
            console.log(location.search)
            console.log(body)
            let title = $('#title')
            title.text(body[0].title)
            console.log(body)
            let date = $('#date')
            date.text(body[0].postTime)
            let preview = $('#preview')
            let src = 'userImage/' + body[1].imageUrl
            console.log(src)
            let img = $(`<img src=${src} alt="" class="via" id="image">`)
            preview.append(img)
            let author = $('.blogger h3')
            author.text(body[1].username)
            $('#email').text(body[1].email)
            $('#age').text(body[1].age)
            $('#location').text(body[1].location)
            $('#profession').text(body[1].profession)
            $('#resume').text(body[1].resume)
            $('#blog-count').text(body[2].blogCountByTotal)
            $('#category-count').text(body[2].categoryCountByTotal)
            if (user == body[1].userId) {
                console.log(1)
                let a = $(`<a href='delete${location.search}'>删除</a>`)
                $('.right').append(a)
            }
            editormd.markdownToHTML('content', {
                markdown : body[0].content
            })

        },
        error: function (body) {
            console.log(body)
        }
    })
}

function uploadVisit() {
    $.ajax({
        url : 'visit' + location.search,
        method: 'get',
        success: function (body) {
            if (body == "访问成功！") console.log("访问成功!")
            else console.log("访问失败1")
        },
        error: function (body) {
            console.log(body)
            console.log("访问失败2")
        }
    })
}